package com.tiptop.mybatis;

import java.util.Date;

import com.google.gson.Gson;
import com.tiptop.mybatis.mapper.UserMapper;
import com.tiptop.mybatis.model.User;
import com.tiptop.mybatis.util.MySqlSession;

public class Test {  
  
    public static void main(String[] args) {  
        try {  
            // 获取对象  
            UserMapper dao = MySqlSession.getMapper(UserMapper.class);  
  
            // 查询相关MYDWT_DM为“1001”的信息  
            User u = dao.load(6L); 
            System.out.println("mybatis查询测试：=================================");  
            System.out.println("user：" + (new Gson()).toJson(u));  
            // 插入数据 
            User u1 = new User();
            u1.setName(u1.toString());
            u1.setCreateTime(new Date());
            dao.create(u1);
            System.out.println("mybatis保存测试：=================================");  
            System.out.println("user：" + (new Gson()).toJson(u1)); 
            
            MySqlSession.commit(); 
            MySqlSession.close();
        } catch (Exception e) {  
        	MySqlSession.rollback();  
        	MySqlSession.close();  
            e.printStackTrace();  
        } 
    }  
} 
